`sas2vsta` | Generate a ViSta input file from a SAS dataset | `sas2vsta`

# SAS Macro Programs: `sas2vsta`

$Version: 1.1
Michael Friendly
York University

## The `sas2vsta` macro ( get sas2vsta.sas)

### Generate a ViSta input file from a SAS dataset

The `SAS2VSTA` macro reads a SAS data set and produces an output file suitable as input to ViSta. Handles multivariate data and frequency classification data. Doesn't handle frequency table data. See: http://forrest.psych.unc.edu/research/ for information about ViSta.

## Usage

The `SAS2VSTA` macro is called with keyword parameters. The VAR= parameter is required. The arguments may be listed within parentheses in any order, separated by commas. For example:

      %sas2vsta(data=new, var=Name Group X1 X2 X3, id=name,
         about=%str(A sample data set, converted to ViSta));

Observations may be selected by the WHERE= parameter. They appear in the output in their order in the input data set. Sort them first if you want some alternative order.

By default, output is written to a file of the same name as the SAS data set, with the extension '.lsp', in the current SAS directory.

### Parameters

DATA=
  The name of the input data set [Default: DATA=_LAST_]
DNAME=
  Data name, the name of the data set for ViSta. [Default: DNAME=&DATA]
VAR=
  List of variable names to be output, a blank separated list. Variables appear in the output in the order listed, and in the `:VARIABLES` list in the case given.
FREQ=
  Name of a frequency variable, if any. Added as the last variable, and the `:FREQ t` flag is set. All other variables are treated as Category variables in this case.
ID=
  The name(s) of observation ID variable(s), which are used as row `:LABELS`. If two or more variables are given, their values are joined using the SEP= character for each observation.
SEP=
  Separator character just to join adjacent ID variables. If you want to use a character which the `SAS` macro processor treats as special, use, e.g., `SEP=%str(,)`.
ABBREV=
  Maximum length of any ID variable when there are 2 or more listed in ID=. If ABBREV= is specified, each ID= variable is abbreviated to this length to construct a single observation label.
WHERE=
  WHERE clause to subset the observations in the output file. Use `WHERE=%str(var=value)` if value contains any funny characters.
TITLE=
  Generate a ViSta input file from a SAS dataset string for the data for ViSta [Default: TITLE=&DATA]
ABOUT=
  `:ABOUT` description; use `%str()` if it contains ','. If not specified, we use the data set label, if there is one. NB: you must use quotes, as in

        data foobar (label="My foobar data");

  for the label to be accessible to this macro.
OUT=
  Output destination, one of `OUT=FILE, PRINT or STDOUT` [Default: OUT=FILE]
OUTFILE=
  Name of output LSP file. [Default: &DATA.lsp]
OUTDIR=
  Name of output directory. [Default: Current SAS directory]
LS=
  Output linesize [Default: 80]

### Example

This example starts with data for a 2 x 2 x 6 contingency table on frequency for Admit x Gender x Dept for admissions to graduate school at Berkeley.

    %include macros(sas2vsta);        *-- or include in an autocall library;

    title 'Berkeley Admissions data';
    proc format;
       value admit 1="Admit" 0="Reject"          ;
       value yn    1="+"        0="-"                 ;
       value dept  1="A" 2="B" 3="C" 4="D" 5="E" 6="F";
    data berkeley (label="Berkeley admissions data");
       do dept = 1 to 6;
          do gender = 'M', 'F';
             do admit = 1, 0;
                input freq @@;
                output;
       end; end; end;
    	format dept dept. admit admit.;
    /* Admit  Rej  Admit Rej */
    cards;
         512  313    89   19
         353  207    17    8
         120  205   202  391
         138  279   131  244
          53  138    94  299
          22  351    24  317
    ;

To create a file, berkeley.lsp for ViSta, with the table variables ordered Gender, Dept, Admit, and the ID= variables separated by '-', use the following macro call:

    %sas2vsta(data=berkeley, var=Gender Dept Admit, freq=Freq,
    	id=Gender Dept Admit, sep=-,
    	about=%str(Berkeley admissions data, from Bickel-etal:75) );

The output file, berkeley.lsp looks like this:

    (DATA "berkeley"
      :TITLE "berkeley"
      :ABOUT "Berkeley admissions data, from Bickel-etal:75"
      :FREQ t
      :VARIABLES (QUOTE ( "Gender" "Dept" "Admit" "Freq"))
      :TYPES (QUOTE ( "Category" "Category" "Category" "Numeric"))
      :LABELS (QUOTE (
       "M-A-Admit" "M-A-Reject" "F-A-Admit" "F-A-Reject" "M-B-Admit" "M-B-Reject"
       "F-B-Admit" "F-B-Reject" "M-C-Admit" "M-C-Reject" "F-C-Admit" "F-C-Reject"
       "M-D-Admit" "M-D-Reject" "F-D-Admit" "F-D-Reject" "M-E-Admit" "M-E-Reject"
       "F-E-Admit" "F-E-Reject" "M-F-Admit" "M-F-Reject" "F-F-Admit" "F-F-Reject"
        ))
      :DATA (QUOTE (
       "M"  "A"  "Admit"  512
       "M"  "A"  "Reject"  313
       "F"  "A"  "Admit"  89
       "F"  "A"  "Reject"  19
       "M"  "B"  "Admit"  353
       "M"  "B"  "Reject"  207
       "F"  "B"  "Admit"  17
       "F"  "B"  "Reject"  8
       "M"  "C"  "Admit"  120
       "M"  "C"  "Reject"  205
       "F"  "C"  "Admit"  202
       "F"  "C"  "Reject"  391
       "M"  "D"  "Admit"  138
       "M"  "D"  "Reject"  279
       "F"  "D"  "Admit"  131
       "F"  "D"  "Reject"  244
       "M"  "E"  "Admit"  53
       "M"  "E"  "Reject"  138
       "F"  "E"  "Admit"  94
       "F"  "E"  "Reject"  299
       "M"  "F"  "Admit"  22
       "M"  "F"  "Reject"  351
       "F"  "F"  "Admit"  24
       "F"  "F"  "Reject"  317
       ))
    )

### See also